{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "# Julia Parallelism Basics"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2-element Array{Int64,1}:\n",
       " 2\n",
       " 3"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "addprocs(2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nworkers()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2-element Array{Int64,1}:\n",
       " 2\n",
       " 3"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "workers()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Future(2, 1, 4, Nullable{Any}())"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r = remotecall(rand, 2, 2, 2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2×2 Array{Float64,2}:\n",
       " 0.197288  0.629904\n",
       " 0.328007  0.315113"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    " fetch(r)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Future(3, 1, 6, Nullable{Any}())"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s = @spawnat 3 1+fetch(r)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2×2 Array{Float64,2}:\n",
       " 1.19729  1.6299 \n",
       " 1.32801  1.31511"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fetch(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.19728790416018938"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "remotecall_fetch(getindex, 2, r, 1, 1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Future(2, 1, 9, Nullable{Any}())"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r = @spawn rand(2,2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Future(3, 1, 10, Nullable{Any}())"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s = @spawn 1+fetch(r)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "rand2 (generic function with 1 method)"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "function rand2(dims...)\n",
    "    return 2*rand(dims...)\n",
    "end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2×2 Array{Float64,2}:\n",
       " 1.81614   1.17952\n",
       " 0.583024  1.99303"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rand2(2,2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Future(2, 1, 11, Nullable{Any}())"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r2 = @spawn rand2(2,2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "outputs": [
    {
     "ename": "LoadError",
     "evalue": "\u001b[91mOn worker 2:\n\u001b[91mUndefVarError: #rand2 not defined\u001b[39m\ndeserialize_datatype at ./serialize.jl:973\nhandle_deserialize at ./serialize.jl:677\ndeserialize at ./serialize.jl:637\nhandle_deserialize at ./serialize.jl:684\ndeserialize_global_from_main at ./distributed/clusterserialize.jl:154\nforeach at ./abstractarray.jl:1733\ndeserialize at ./distributed/clusterserialize.jl:56\nhandle_deserialize at ./serialize.jl:726\ndeserialize at ./serialize.jl:637\nhandle_deserialize at ./serialize.jl:681\ndeserialize at ./serialize.jl:637\nhandle_deserialize at ./serialize.jl:684\ndeserialize_msg at ./distributed/messages.jl:98\nmessage_handler_loop at ./distributed/process_messages.jl:161\nprocess_tcp_streams at ./distributed/process_messages.jl:118\n#99 at ./event.jl:73\u001b[39m",
     "output_type": "error",
     "traceback": [
      "\u001b[91mOn worker 2:\n\u001b[91mUndefVarError: #rand2 not defined\u001b[39m\ndeserialize_datatype at ./serialize.jl:973\nhandle_deserialize at ./serialize.jl:677\ndeserialize at ./serialize.jl:637\nhandle_deserialize at ./serialize.jl:684\ndeserialize_global_from_main at ./distributed/clusterserialize.jl:154\nforeach at ./abstractarray.jl:1733\ndeserialize at ./distributed/clusterserialize.jl:56\nhandle_deserialize at ./serialize.jl:726\ndeserialize at ./serialize.jl:637\nhandle_deserialize at ./serialize.jl:681\ndeserialize at ./serialize.jl:637\nhandle_deserialize at ./serialize.jl:684\ndeserialize_msg at ./distributed/messages.jl:98\nmessage_handler_loop at ./distributed/process_messages.jl:161\nprocess_tcp_streams at ./distributed/process_messages.jl:118\n#99 at ./event.jl:73\u001b[39m",
      "",
      "Stacktrace:",
      " [1] \u001b[1m#remotecall_fetch#141\u001b[22m\u001b[22m\u001b[1m(\u001b[22m\u001b[22m::Array{Any,1}, ::Function, ::Function, ::Base.Distributed.Worker, ::Base.Distributed.RRID, ::Vararg{Any,N} where N\u001b[1m)\u001b[22m\u001b[22m at \u001b[1m./distributed/remotecall.jl:354\u001b[22m\u001b[22m",
      " [2] \u001b[1mremotecall_fetch\u001b[22m\u001b[22m\u001b[1m(\u001b[22m\u001b[22m::Function, ::Base.Distributed.Worker, ::Base.Distributed.RRID, ::Vararg{Any,N} where N\u001b[1m)\u001b[22m\u001b[22m at \u001b[1m./distributed/remotecall.jl:346\u001b[22m\u001b[22m",
      " [3] \u001b[1m#remotecall_fetch#144\u001b[22m\u001b[22m\u001b[1m(\u001b[22m\u001b[22m::Array{Any,1}, ::Function, ::Function, ::Int64, ::Base.Distributed.RRID, ::Vararg{Any,N} where N\u001b[1m)\u001b[22m\u001b[22m at \u001b[1m./distributed/remotecall.jl:367\u001b[22m\u001b[22m",
      " [4] \u001b[1mcall_on_owner\u001b[22m\u001b[22m\u001b[1m(\u001b[22m\u001b[22m::Function, ::Future\u001b[1m)\u001b[22m\u001b[22m at \u001b[1m./distributed/remotecall.jl:440\u001b[22m\u001b[22m",
      " [5] \u001b[1mfetch\u001b[22m\u001b[22m\u001b[1m(\u001b[22m\u001b[22m::Future\u001b[1m)\u001b[22m\u001b[22m at \u001b[1m./distributed/remotecall.jl:460\u001b[22m\u001b[22m"
     ]
    }
   ],
   "source": [
    "fetch(r2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "outputs": [],
   "source": [
    "@everywhere function rand2(dims...)\n",
    "    return 2*rand(dims...)\n",
    "end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2×2 Array{Float64,2}:\n",
       " 0.48609   1.06869 \n",
       " 0.275809  0.241942"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r2 = @spawn rand2(2,2)\n",
    "fetch(r2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## Data Movement"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  0.209178 seconds (323 allocations: 15.270 MiB, 49.92% gc time)\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "1000×1000 Array{Float64,2}:\n",
       " 259.909  250.942  256.955  253.812  …  252.901  250.257  265.245  258.605\n",
       " 257.849  248.031  254.137  259.737     255.823  247.793  261.132  255.321\n",
       " 266.534  257.839  257.644  258.331     257.45   252.531  267.849  259.745\n",
       " 259.85   253.181  253.874  255.347     252.351  242.975  265.12   258.404\n",
       " 256.592  248.026  251.564  257.389     254.352  248.764  259.832  255.358\n",
       " 260.583  254.463  254.889  248.373  …  247.386  253.957  258.725  252.433\n",
       " 260.79   255.477  261.272  263.816     260.569  254.48   269.198  266.2  \n",
       " 255.936  246.098  251.435  249.117     248.44   244.648  262.274  253.384\n",
       " 254.021  245.83   248.266  251.313     246.582  240.981  255.547  248.779\n",
       " 253.917  250.891  247.666  253.851     248.124  247.972  255.63   251.605\n",
       " 264.302  259.857  260.422  263.348  …  262.938  252.856  267.633  263.638\n",
       " 266.4    263.05   265.823  259.581     262.129  255.302  270.063  266.505\n",
       " 242.967  241.852  240.739  242.858     242.499  235.089  251.127  243.952\n",
       "   ⋮                                 ⋱                                    \n",
       " 251.693  247.826  247.214  250.642     243.865  241.637  252.796  250.582\n",
       " 263.39   253.013  254.097  255.848     249.798  252.018  260.84   256.526\n",
       " 251.784  249.862  252.182  257.051  …  248.276  249.069  260.76   252.263\n",
       " 256.148  255.998  257.143  256.909     253.006  251.571  261.218  260.598\n",
       " 249.138  249.41   246.957  248.58      239.949  239.344  249.28   248.236\n",
       " 250.657  247.74   252.116  251.229     248.666  244.72   254.068  255.285\n",
       " 256.18   249.137  253.842  255.423     254.383  244.297  256.582  257.687\n",
       " 254.925  241.423  247.256  251.384  …  245.819  244.043  252.304  249.286\n",
       " 258.729  247.379  258.517  252.514     247.085  245.328  258.361  255.916\n",
       " 253.762  253.039  250.831  249.454     244.308  243.941  254.744  248.125\n",
       " 253.92   244.562  248.783  249.405     243.808  240.691  248.387  247.19 \n",
       " 256.703  250.396  252.98   256.269     253.051  245.302  263.74   252.039"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "@time begin \n",
    "    A = rand(1000,1000)\n",
    "    Bref = @spawn A^2\n",
    "    fetch(Bref)\n",
    "end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  0.086037 seconds (296 allocations: 7.639 MiB)\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "1000×1000 Array{Float64,2}:\n",
       " 243.806  243.64   252.726  244.483  …  253.424  248.386  243.628  246.184\n",
       " 250.03   246.795  256.952  250.109     253.873  258.346  246.432  246.619\n",
       " 259.294  253.378  262.675  255.474     261.308  259.71   254.755  262.798\n",
       " 252.465  248.929  258.608  250.546     262.352  255.575  250.516  250.077\n",
       " 255.096  245.706  260.887  254.912     256.119  254.285  248.993  250.773\n",
       " 248.316  243.437  254.808  249.25   …  252.433  246.096  240.356  247.763\n",
       " 247.531  241.044  252.041  251.16      247.67   247.144  239.434  241.214\n",
       " 258.228  249.972  259.064  254.262     256.265  251.418  246.76   253.417\n",
       " 258.763  244.008  258.74   250.972     254.936  253.824  253.512  257.931\n",
       " 255.136  246.773  261.987  260.319     260.321  256.937  247.253  248.99 \n",
       " 243.768  243.328  257.77   244.062  …  251.221  253.141  241.353  245.661\n",
       " 254.772  246.124  254.704  249.421     251.301  248.194  242.888  247.089\n",
       " 248.59   247.096  253.851  249.837     254.093  251.694  246.354  247.471\n",
       "   ⋮                                 ⋱                                    \n",
       " 237.564  237.817  251.26   243.939     241.994  244.824  239.145  237.569\n",
       " 256.919  254.376  265.558  251.382     257.756  257.328  246.821  250.321\n",
       " 247.492  244.216  255.082  248.3    …  254.08   253.283  244.904  245.454\n",
       " 260.05   256.495  265.976  256.66      259.47   258.728  255.032  262.166\n",
       " 257.301  253.106  268.218  256.201     267.061  255.147  254.483  259.402\n",
       " 257.059  253.224  266.537  254.847     260.124  262.089  253.134  256.273\n",
       " 253.092  256.058  263.143  252.992     254.477  255.606  252.943  253.015\n",
       " 257.226  250.355  262.236  253.122  …  260.622  257.704  249.114  256.294\n",
       " 259.914  248.89   262.219  256.196     261.237  252.595  255.642  255.228\n",
       " 246.385  248.051  252.385  250.465     254.06   253.988  247.669  246.373\n",
       " 253.088  243.502  252.064  246.346     244.106  252.565  239.35   241.096\n",
       " 249.981  242.683  254.803  249.6       254.763  249.892  242.835  250.089"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "@time begin\n",
    "    Bref = @spawn rand(1000,1000)^2\n",
    "    fetch(Bref)\n",
    "end"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## Shared Arrays\n",
    "\n",
    "Shared Arrays are created by mapping the same region in memory to different processes. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "100×100 SharedArray{Float64,2}:\n",
       " 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  …  0.0  0.0  0.0  0.0  0.0  0.0  0.0\n",
       " 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0     0.0  0.0  0.0  0.0  0.0  0.0  0.0\n",
       " 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0     0.0  0.0  0.0  0.0  0.0  0.0  0.0\n",
       " 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0     0.0  0.0  0.0  0.0  0.0  0.0  0.0\n",
       " 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0     0.0  0.0  0.0  0.0  0.0  0.0  0.0\n",
       " 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  …  0.0  0.0  0.0  0.0  0.0  0.0  0.0\n",
       " 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0     0.0  0.0  0.0  0.0  0.0  0.0  0.0\n",
       " 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0     0.0  0.0  0.0  0.0  0.0  0.0  0.0\n",
       " 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0     0.0  0.0  0.0  0.0  0.0  0.0  0.0\n",
       " 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0     0.0  0.0  0.0  0.0  0.0  0.0  0.0\n",
       " 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  …  0.0  0.0  0.0  0.0  0.0  0.0  0.0\n",
       " 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0     0.0  0.0  0.0  0.0  0.0  0.0  0.0\n",
       " 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0     0.0  0.0  0.0  0.0  0.0  0.0  0.0\n",
       " ⋮                        ⋮              ⋱            ⋮                      \n",
       " 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0     0.0  0.0  0.0  0.0  0.0  0.0  0.0\n",
       " 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0     0.0  0.0  0.0  0.0  0.0  0.0  0.0\n",
       " 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  …  0.0  0.0  0.0  0.0  0.0  0.0  0.0\n",
       " 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0     0.0  0.0  0.0  0.0  0.0  0.0  0.0\n",
       " 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0     0.0  0.0  0.0  0.0  0.0  0.0  0.0\n",
       " 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0     0.0  0.0  0.0  0.0  0.0  0.0  0.0\n",
       " 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0     0.0  0.0  0.0  0.0  0.0  0.0  0.0\n",
       " 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  …  0.0  0.0  0.0  0.0  0.0  0.0  0.0\n",
       " 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0     0.0  0.0  0.0  0.0  0.0  0.0  0.0\n",
       " 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0     0.0  0.0  0.0  0.0  0.0  0.0  0.0\n",
       " 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0     0.0  0.0  0.0  0.0  0.0  0.0  0.0\n",
       " 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0     0.0  0.0  0.0  0.0  0.0  0.0  0.0"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s = SharedArray{Float64}(100,100)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1:0"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "localindexes(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1:5000"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fetch(@spawnat 2 localindexes(s))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5001:10000"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fetch(@spawnat 3 localindexes(s))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "outputs": [],
   "source": [
    "for i in workers()\n",
    "    @spawnat i s[localindexes(s)] = myid()\n",
    "end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "100×100 SharedArray{Float64,2}:\n",
       " 2.0  2.0  2.0  2.0  2.0  2.0  2.0  2.0  …  3.0  3.0  3.0  3.0  3.0  3.0  3.0\n",
       " 2.0  2.0  2.0  2.0  2.0  2.0  2.0  2.0     3.0  3.0  3.0  3.0  3.0  3.0  3.0\n",
       " 2.0  2.0  2.0  2.0  2.0  2.0  2.0  2.0     3.0  3.0  3.0  3.0  3.0  3.0  3.0\n",
       " 2.0  2.0  2.0  2.0  2.0  2.0  2.0  2.0     3.0  3.0  3.0  3.0  3.0  3.0  3.0\n",
       " 2.0  2.0  2.0  2.0  2.0  2.0  2.0  2.0     3.0  3.0  3.0  3.0  3.0  3.0  3.0\n",
       " 2.0  2.0  2.0  2.0  2.0  2.0  2.0  2.0  …  3.0  3.0  3.0  3.0  3.0  3.0  3.0\n",
       " 2.0  2.0  2.0  2.0  2.0  2.0  2.0  2.0     3.0  3.0  3.0  3.0  3.0  3.0  3.0\n",
       " 2.0  2.0  2.0  2.0  2.0  2.0  2.0  2.0     3.0  3.0  3.0  3.0  3.0  3.0  3.0\n",
       " 2.0  2.0  2.0  2.0  2.0  2.0  2.0  2.0     3.0  3.0  3.0  3.0  3.0  3.0  3.0\n",
       " 2.0  2.0  2.0  2.0  2.0  2.0  2.0  2.0     3.0  3.0  3.0  3.0  3.0  3.0  3.0\n",
       " 2.0  2.0  2.0  2.0  2.0  2.0  2.0  2.0  …  3.0  3.0  3.0  3.0  3.0  3.0  3.0\n",
       " 2.0  2.0  2.0  2.0  2.0  2.0  2.0  2.0     3.0  3.0  3.0  3.0  3.0  3.0  3.0\n",
       " 2.0  2.0  2.0  2.0  2.0  2.0  2.0  2.0     3.0  3.0  3.0  3.0  3.0  3.0  3.0\n",
       " ⋮                        ⋮              ⋱            ⋮                      \n",
       " 2.0  2.0  2.0  2.0  2.0  2.0  2.0  2.0     3.0  3.0  3.0  3.0  3.0  3.0  3.0\n",
       " 2.0  2.0  2.0  2.0  2.0  2.0  2.0  2.0     3.0  3.0  3.0  3.0  3.0  3.0  3.0\n",
       " 2.0  2.0  2.0  2.0  2.0  2.0  2.0  2.0  …  3.0  3.0  3.0  3.0  3.0  3.0  3.0\n",
       " 2.0  2.0  2.0  2.0  2.0  2.0  2.0  2.0     3.0  3.0  3.0  3.0  3.0  3.0  3.0\n",
       " 2.0  2.0  2.0  2.0  2.0  2.0  2.0  2.0     3.0  3.0  3.0  3.0  3.0  3.0  3.0\n",
       " 2.0  2.0  2.0  2.0  2.0  2.0  2.0  2.0     3.0  3.0  3.0  3.0  3.0  3.0  3.0\n",
       " 2.0  2.0  2.0  2.0  2.0  2.0  2.0  2.0     3.0  3.0  3.0  3.0  3.0  3.0  3.0\n",
       " 2.0  2.0  2.0  2.0  2.0  2.0  2.0  2.0  …  3.0  3.0  3.0  3.0  3.0  3.0  3.0\n",
       " 2.0  2.0  2.0  2.0  2.0  2.0  2.0  2.0     3.0  3.0  3.0  3.0  3.0  3.0  3.0\n",
       " 2.0  2.0  2.0  2.0  2.0  2.0  2.0  2.0     3.0  3.0  3.0  3.0  3.0  3.0  3.0\n",
       " 2.0  2.0  2.0  2.0  2.0  2.0  2.0  2.0     3.0  3.0  3.0  3.0  3.0  3.0  3.0\n",
       " 2.0  2.0  2.0  2.0  2.0  2.0  2.0  2.0     3.0  3.0  3.0  3.0  3.0  3.0  3.0"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3.0"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fetch(@spawnat 2 s[100,100])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2.0"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fetch(@spawnat 3 s[1,1])"
   ]
  }
 ],
 "metadata": {
  "celltoolbar": "Slideshow",
  "kernelspec": {
   "display_name": "Julia 0.6.2",
   "language": "julia",
   "name": "julia-0.6"
  },
  "language_info": {
   "file_extension": ".jl",
   "mimetype": "application/julia",
   "name": "julia",
   "version": "0.6.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
